package wechat.service.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import wechat.service.common.PayUserAgent;
import wechat.service.common.SwitchResources;

/**
 * Servlet implementation class CenterServiceServlet
 */
@WebServlet("/CenterServiceServlet")
public class CenterServiceServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	private Logger log = LoggerFactory.getLogger(CenterServiceServlet.class);
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CenterServiceServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * 前置服务
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String userAgent = request.getHeader("User-Agent");
		String state = request.getParameter("state");
		String payCode = request.getParameter("payCode");
		String appid = request.getAttribute("appid").toString();
		
		log.info("CenterServiceServlet Get userAgent=" + userAgent);
		log.info("CenterServiceServlet Get appid=" + appid + " state=" + state);
		
		String url =  SwitchResources.getUrlResources(appid,state,userAgent);
		
		log.info("CenterServiceServlet Get url=" + url);
		if ("".equals(url)) {
			return;
		}
		
		response.sendRedirect(url);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

}
